#include "DATReader.h"
#include "DATObject.h"

#include "time.h"
#include <sstream>

int main(int argc,char* argv[])
{
	if(argc > 4 || argc < 3)
	{
		cout<<"Usage: DATReader.exe XMLFilename SequenceFilename [-v]"<<endl;
		system("pause");
		return -1;
	}
	std::string lXMLFilename(argv[1]);
	std::string lVideoFilename(argv[2]);
	DATReader lDATReader;
	
	bool lLoadOk = false;
	bool lPlayOk = false;

	//Load functions
	lLoadOk = lDATReader.loadXMLFile(lXMLFilename);
	if(!lLoadOk)
	{
		std::cerr<<"XML loading error : "<<lXMLFilename<<"."<<std::endl;
		return -1;
	}
	lLoadOk = lDATReader.loadVideoFeed(lVideoFilename);
	if(!lLoadOk)
	{
		std::cerr<<"Video loading error : "<<lVideoFilename<<"."<<std::endl;
		return -1;
	}

	map<string,CvScalar> lColors;
	lColors[""] = CV_RGB(102,0,153);
	lColors["RSide"] = CV_RGB(255.0,0,0);
	lColors["LSide"] = CV_RGB(255.0,255.0,0);
	lColors["Rear"] = CV_RGB(0,0,255.0);
	lColors["Front"] = CV_RGB(0,255.0,0);

	//Play the XML on the feed (duh)
	//lDATReader.setStartingFrame(120);
	lDATReader.setColorScheme(lColors);
	if(argc == 4 && string(argv[3])=="-v")
		lPlayOk = lDATReader.playXML(0,false,true,false);	
	else
		lPlayOk = lDATReader.playXML(-2,true,false);
		
	if(!lPlayOk)
	{
		std::cerr<<"Playing error : Probably a loading error..."<<std::endl;
		std::cerr<<"If not, look for a CODEC error..."<<std::endl;
		system("pause");
		return -2;
	}
	return 0;
}